/*********************
* Author:Dzlua
* QQ:505544956
* time:2016/08/13
*/
#ifndef __EDUI_SDL_FONT_H__
#define __EDUI_SDL_FONT_H__

#include "SDL.h"
#include "SDL_ttf.h"
#include "edui/interface/IEngine.h"

EDUI_NAMESPACE_BEGIN
	
class Font : public IFont
{
protected:
    Font();
    virtual ~Font();
public:
	static Font* GetInterface();
	virtual void Release();
    static Font* ToFont(IFont* font);
#ifdef EDUI_TEST_NEW_DELETE
    static int m_newdeleteNum;
    static int _GetNewDeleteNum();
#endif
public:
	/* if not name.
	       Create("font.ttf", 12, 0);
	   add to mgr as: default name is "font.ttf-12"
	*/
	virtual bool Create(const char* file, int size, const char* name = 0, int id = -1);

	/* if not name.
	       Create("font.ttf", 12, 1, 0);
	   add to mgr as: default name is "font.ttf-12-1"
	*/
	virtual bool Create(const char* file, int size, long idx, const char* name = 0, int id = -1);

	// create use this function, you must Destroy and Release this font.
	virtual bool Create(TTF_Font* font);

	virtual bool IsOK();
	virtual void Destroy();

	virtual int GetHeight();

	/* Set and retrieve the font style */
	virtual void SetStyle(int style);
	virtual int  GetStyle();
	virtual void SetOutline(int outline);
	virtual int  GetOutline();
	virtual void SetStyle(bool bold, bool italic, bool underline, bool strikethrough);

	/* Set and retrieve FreeType hinter settings */
	virtual void SetHinting(FontHinting hinting);
	virtual FontHinting GetHinting();

	/* Get the offset from the baseline to the top of the font
	This is a positive value, relative to the baseline.
	*/
	virtual int Ascent();

	/* Get the offset from the baseline to the bottom of the font
	This is a negative value, relative to the baseline.
	*/
	virtual int Descent();

	/* Get the recommended spacing between lines of text for this font */
	virtual int LineSkip();

	/* Get/Set whether or not kerning is allowed for this font */
	virtual void SetKerning(bool allowed);
	virtual int GetKerning();

	/* Get the number of faces of the font */
	virtual long Faces();

	/* Get the font face attributes, if any */
	virtual int  FaceIsFixedWidth();
	virtual char* FaceFamilyName();
	virtual char* FaceStyleName();

	/* Check wether a glyph is provided by the font or not */
	virtual int GlyphIsProvided(Uint16 ch);

	/* Get the metrics (dimensions) of a glyph
	   To understand what these metrics mean, here is a useful link:
	   http://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html
	*/
	virtual int GlyphMetrics(Uint16 ch, int *minx, int *maxx,
                              int *miny, int *maxy, int *advance);

	/* Get the dimensions of a rendered string of text */
	virtual Size GetSize(const char *text);
	virtual Size GetSizeUTF8(const char *text);
	virtual Size GetSizeUNICODE(const Uint16 *text);

	/* Get the kerning size of two glyphs */
	virtual int GetKerningSizeGlyphs(Uint16 previous_ch, Uint16 ch);

	virtual ITexture* RenderText(IRender* render, const char* text, const Color* fg);

public:
	TTF_Font* GetTTFFont() const;
protected:
    TTF_Font* m_font;
};

EDUI_NAMESPACE_END

#endif